const { uploadToQiniu } = require('../utils/upload');
const { sendResponse, sendError } = require('../utils/response');

//七牛云文件上传
exports.qiniuUpload = async (req, res) => {
    try {
        
        if (!req.file) {
            throw new Error('请选择文件!');
        }
        
        const result = await uploadToQiniu(req.file)

        if(!result){
            sendError(res, result, 500);          
        }

        sendResponse(res, {
            success: true,
            url: result.url,
            type: result.type
        }, 200, '上传成功！');

    } catch (error) {
        sendError(res, error.message, 500);
    }
}